package fun.util.daohelper;

import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: bin
 * Date: Jan 9, 2006
 * Time: 10:35:39 PM
 * To change this template use File | Settings | File Templates.
 */
public class AbstractPrimaryKey<D extends Serializable> implements PrimaryKey<D>, Serializable {

    D value;

    protected AbstractPrimaryKey(D value) {
        this.value = value;
    }

    public D getValue() {
        return value;
    }

    public int hashCode() {
        return value == null ? super.hashCode() : value.hashCode();
    }

    public boolean equals(Object obj) {
        return equals((AbstractPrimaryKey) obj);
    }

    public boolean equals(AbstractPrimaryKey pk) {
        if (this == pk) {
            return true;
        }
        if (value == null || pk == null) {
            return false;
        }
        return value.equals(pk.value);
    }


    public String toString() {
        return PrimaryKeyUtil.serializePK(this);
    }
}
